package com.cuz.daileetcode.h100;

import com.cuz.daileetcode.utils.TreeNode;

public class P111 {

    public static void main(String[] args) {
        //2,null,3,null,4,null,5,null,6
        TreeNode t2 = new TreeNode(2);
        TreeNode t3 = new TreeNode(3);
        TreeNode t4 = new TreeNode(4);
        TreeNode t5 = new TreeNode(5);
        TreeNode t6 = new TreeNode(6);
        t2.right = t3;
        t3.right = t4;
        t4.right = t5;
        t5.right = t6;
        System.out.println(new P111().minDepth(t2));
    }

    public int minDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        if (root.left == null && root.right == null) {
            return 1;
        }
        int num = Integer.MAX_VALUE;

        if (root.left != null) {
            num = Math.min(num, minDepth(root.left));
        }
        if (root.right != null) {
            num = Math.min(num, minDepth(root.right));
        }
        return num + 1;
    }
}
